import { createApp } from 'vue'
import App from './App.vue'
import './registerServiceWorker'
import router from './router'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import ElementPlus from "element-plus"
import zhCn from 'element-plus/es/locale/lang/zh-cn'

import { Button } from 'vant';

const app = createApp(App)
//通过app遍历所有组件 修改配置 进行图标注册
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}

const debounce = (fn: any, delay: any) => {
    let timer: any
    return (...args: any) => {
        if (timer) {
            clearTimeout(timer)
        }
        timer = setTimeout(() => {
            fn(...args)
        }, delay)
    }
}
const _ResizeObserver = window.ResizeObserver;
window.ResizeObserver = class ResizeObserver extends _ResizeObserver {
    constructor(callback: any) {
        callback = debounce(callback, 200);
        super(callback);
    }
}

app.use(Button);
app.use(ElementPlus, {
    locale: zhCn
})
app.use(router)
app.mount('#app')